﻿import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.15
import QtGraphicalEffects 1.15

/*
  登录界面
*/

Item {
    id:backGround
    width: screenWidth
    height: screenHeight

    property bool plcLinkState: Cpp_Connect.PLC_State

    Image {
        anchors.fill: backGround
        source: "qrc:/Image/Login_backGround.jpg"

        MouseArea{
            anchors.fill: parent
            // enabled: plcLinkState && !connectSettingWindow.visible

            onClicked: {
                loginWindow.visible = false
                processWindow.visible = true
            }
        }
    }

    Text{
        anchors.left: backGround.left
        anchors.leftMargin: 10
        anchors.top: backGround.top
        // anchors.topMargin: 970
        font.pixelSize: 30
        color: "white"
        text:qsTr("语言切换:")
        visible: true
    }

    ComboBox{       // 扫码枪 - 校验位选择框
        id:language
        anchors.left: backGround.left
        anchors.leftMargin: 10
        anchors.top: backGround.top
        anchors.topMargin: 50
        width: 200
        height: 30
        model:["中文","English","Việt nam"]
        currentIndex: 0
        visible: true

        contentItem: Text {     //界面上显示出来的文字
            leftPadding: 20      //左部填充为5
            text: language.displayText   //表示ComboBox上显示的文本
            // font: language.font          //文字大小
            color: language.enabled ? "black" : "grey"   //language.pressed ?
            verticalAlignment: Text.AlignVCenter        //文字位置
        }

        background: Rectangle {   //背景项
            implicitWidth: 120
            implicitHeight: 30
            property string sColor: language.enabled ? "white" : "lightgrey"
            color: language.pressed ? Qt.darker(sColor, 1.2) : sColor
            border.width: 1
            border.color: "lightgrey"
            radius: 0
        }


        onActivated: {
            Cpp_translator.load(currentIndex);
        }
    }

    Rectangle{      // 连接状态
        anchors.top: backGround.top
        anchors.topMargin: 10
        anchors.horizontalCenter: backGround.horizontalCenter
        color: "transparent"
        border.width: 1
        border.color: "white"
        width: 200
        height: 80

        Text{            
            anchors.centerIn: parent
            font.pixelSize: 50
            color: "red"
            text:plcLinkState ? qsTr("已连接") : qsTr("未连接")
        }
    }

    Rectangle{      // 关闭按钮
        anchors.right: backGround.right
        anchors.rightMargin: 10
        anchors.top: backGround.top
        // anchors.topMargin: 50
        radius: 10
        width: 130
        height: 80
        color: "transparent"
        border.width: 1
        border.color: parent.btn_flag ? "gray" : "white"

        property bool btn_flag: false

        Text{
            anchors.verticalCenter: parent.verticalCenter
            anchors.right: parent.right
            anchors.rightMargin: 10
            font.pixelSize: 30
            color: parent.btn_flag ? "gray" : "white"
            text:"关闭"
        }

        Image {
            id:turnOff_Img
            anchors.left: parent.left
            anchors.leftMargin: 10
            anchors.verticalCenter: parent.verticalCenter
            width: 30
            height: 30
            visible: false
            source: "qrc:/Image/TurnOff.png"
        }

        ColorOverlay{
            anchors.fill: turnOff_Img
            source: turnOff_Img
            color: parent.btn_flag ? "gray" : "white"
        }

        MouseArea{
            anchors.fill: parent

            onEntered: {
                parent.btn_flag = true
            }

            onExited: {
                parent.btn_flag = false
                Qt.quit()
            }
        }
    }


    Rectangle{      // 标题
        anchors.top: backGround.top
        anchors.topMargin: 500
        anchors.horizontalCenter: backGround.horizontalCenter
        width: 800
        height: 400
        color: "transparent"

        Text{
            anchors.top: parent.top
            anchors.topMargin: 50
            anchors.horizontalCenter: parent.horizontalCenter
            font.pixelSize: 120
            color: "gold"
            text:qsTr("双头数控锯")
        }
        Text{
            anchors.top: parent.top
            anchors.topMargin: 200
            anchors.horizontalCenter: parent.horizontalCenter
            font.pixelSize: 100
            color: "gold"
            text:qsTr("操控系统")
        }
    }

    Component.onCompleted: {
        dateShow_Text.text = Qt.formatDateTime(new Date(), "yyyy-MM-dd")
        timeShow_Text.text = Qt.formatDateTime(new Date(), "hh:mm:ss")
    }

    Timer{
        repeat: true
        running: true
        onTriggered: {
            dateShow_Text.text = Qt.formatDateTime(new Date(), "yyyy-MM-dd")
            timeShow_Text.text = Qt.formatDateTime(new Date(), "hh:mm:ss")
        }
    }

    Text{
        id:dateShow_Text
        anchors.horizontalCenter: backGround.horizontalCenter
        anchors.top: backGround.top
        anchors.topMargin: 150
        font.pixelSize: 80
        color: "white"
    }

    Text{
        id:timeShow_Text
        anchors.horizontalCenter: backGround.horizontalCenter
        anchors.top: backGround.top
        anchors.topMargin: 250
        font.pixelSize: 80
        color: "white"
    }

    Rectangle{      // 连接参数区域 - 隐藏按钮
        anchors.left: backGround.left
        anchors.bottom: backGround.bottom
        width: screenWidth / 2
        height: screenHeight * 0.3
        color:"transparent"

        MouseArea{
            anchors.fill: parent
            propagateComposedEvents: true   // 鼠标穿透
            pressAndHoldInterval: 2000
            onPressAndHold: {
                // console.log("隐藏区域显示")
                connectSettingWindow.open()
            }
        }
    }


    Text{
        anchors.right: backGround.right
        anchors.rightMargin: 30
        anchors.bottom: backGround.bottom
        anchors.bottomMargin: 50
        font.pixelSize: 30
        font.bold: true
        color: "white"
        text: qsTr("V 1.0")
    }









}
